//
//  LGTeamMemberCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/16.
//  团队成员

#import "LGTeamMemberCell.h"

@interface LGTeamMemberCell()
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *selectBtn;
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *professLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGTeamMemberCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.clipsToBounds = YES;
        self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        [self.contentView addSubview:self.baseView];
        [self.contentView addSubview:self.selectBtn];
        [self.contentView addSubview:self.headPic];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.professLabel];
        [self.contentView addSubview:self.tipView];
        [self.contentView addSubview:self.lineView];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(viewPix(16));
            make.top.equalTo(self.contentView).offset(-10);
            make.bottom.equalTo(self.contentView).offset(10);
            make.right.equalTo(self.contentView).offset(-viewPix(16));
        }];
    }
    return  self;
}

-(void)setType:(NSString *)type{
    _type = type;
    if([type isEqualToString:@"manage"]){
        self.selectBtn.userInteractionEnabled = NO;
    }else{
        self.selectBtn.userInteractionEnabled = YES;
    }
}

-(void)setModel:(LGTeamMemberModel *)model{
    _model = model;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:defaultDoctorPic];
    self.nameLabel.text = model.realname;
    self.professLabel.text = model.profess;
    if(model.isinto == YES){
        [self.selectBtn setImage:[UIImage imageNamed:@"unEdit24"] forState:UIControlStateNormal];
        self.selectBtn.userInteractionEnabled = NO;
    }else{
        [self.selectBtn setImage:[UIImage imageNamed:@"unselect24"] forState:UIControlStateNormal];
        self.selectBtn.userInteractionEnabled = YES;
    }
}

-(void)setIsSelect:(BOOL)isSelect{
    _isSelect = isSelect;
    self.selectBtn.selected = isSelect;
}

-(void)selectBtnAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    if(self.delegate && [self.delegate respondsToSelector:@selector(selectTeamMember:select:)]){
        [self.delegate selectTeamMember:self.model.userid select:sender.selected];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}
-(UIButton *)selectBtn{
    if(!_selectBtn){
        _selectBtn = [UIButton buttonWithImage:@"unselect24" selectImage:@"selected24"];
        _selectBtn.frame = CGRectMake(viewPix(16), 0, viewPix(58), viewPix(56));
        [_selectBtn addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectBtn;
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(72), viewPix(8), viewPix(42), viewPix(42))];
        _headPic.backgroundColor = [UIColor colorWithString:@"#EEEEEE"];
        _headPic.cornerRidus = 5;
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.frame = CGRectMake(viewPix(134), viewPix(8), viewPix(150), viewPix(23));
    }
    return _nameLabel;
}

-(UILabel *)professLabel{
    if(!_professLabel){
        _professLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _professLabel.frame = CGRectMake(viewPix(134), kMaxY(self.nameLabel.frame), viewPix(150), viewPix(20));
    }
    return _professLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
        _tipView.frame = CGRectMake(Screen_W-viewPix(48), viewPix(21), viewPix(16), viewPix(16));
    }
    return _tipView;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(32), viewPix(58)-0.5, Screen_W-viewPix(64), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E1E1E1"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
